#pragma once

#ifndef NTK_VS_H
#include "ntk_vs.h"
#endif
#ifndef STDIO_H
#include <stdio.h>
#endif
#ifndef DATASTRUCTUREN_H
#include "DataStructuren.h"
#endif
#ifndef HOOFD_H
#include "Hoofd.h"
#endif

namespace CruiseControl {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	
	mailBox *eigenData;
	Input input;
	task *autohoofd;

	mailBox *knop, *snelheid, *pedaalstand;	
	mailBox *actie;							
	event *updateView;					
	event *autogestart_event;

	/// <summary>
	/// Summary for Form1
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}
#pragma region gegenereerde code
	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  buttonStartAuto;
	protected: 

	private: System::Windows::Forms::Button^  buttonPauze;
	private: System::Windows::Forms::Button^  buttonSnelheidVerhogen;
	private: System::Windows::Forms::Button^  buttonSnelheidVerlagen;
	private: System::Windows::Forms::VScrollBar^  ScrollBarKoppeling;
	private: System::Windows::Forms::VScrollBar^  ScrollBarRem;
	private: System::Windows::Forms::VScrollBar^  ScrollBarGas;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Button^  buttonActivatie;


	private: System::Windows::Forms::Label^  labelIngesteldeSnelheid;
	private: System::Windows::Forms::Label^  labelIngesteld;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Label^  label4;

	protected: 

	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->buttonStartAuto = (gcnew System::Windows::Forms::Button());
			this->buttonPauze = (gcnew System::Windows::Forms::Button());
			this->buttonSnelheidVerhogen = (gcnew System::Windows::Forms::Button());
			this->buttonSnelheidVerlagen = (gcnew System::Windows::Forms::Button());
			this->ScrollBarKoppeling = (gcnew System::Windows::Forms::VScrollBar());
			this->ScrollBarRem = (gcnew System::Windows::Forms::VScrollBar());
			this->ScrollBarGas = (gcnew System::Windows::Forms::VScrollBar());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->buttonActivatie = (gcnew System::Windows::Forms::Button());
			this->labelIngesteldeSnelheid = (gcnew System::Windows::Forms::Label());
			this->labelIngesteld = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->label4 = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// buttonStartAuto
			// 
			this->buttonStartAuto->Location = System::Drawing::Point(12, 12);
			this->buttonStartAuto->Name = L"buttonStartAuto";
			this->buttonStartAuto->Size = System::Drawing::Size(75, 23);
			this->buttonStartAuto->TabIndex = 0;
			this->buttonStartAuto->Text = L"Start auto";
			this->buttonStartAuto->UseVisualStyleBackColor = true;
			this->buttonStartAuto->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// buttonPauze
			// 
			this->buttonPauze->Location = System::Drawing::Point(93, 169);
			this->buttonPauze->Name = L"buttonPauze";
			this->buttonPauze->Size = System::Drawing::Size(75, 23);
			this->buttonPauze->TabIndex = 1;
			this->buttonPauze->Text = L"Pauze";
			this->buttonPauze->UseVisualStyleBackColor = true;
			this->buttonPauze->Click += gcnew System::EventHandler(this, &Form1::buttonPauze_Click);
			// 
			// buttonSnelheidVerhogen
			// 
			this->buttonSnelheidVerhogen->Location = System::Drawing::Point(174, 169);
			this->buttonSnelheidVerhogen->Name = L"buttonSnelheidVerhogen";
			this->buttonSnelheidVerhogen->Size = System::Drawing::Size(32, 23);
			this->buttonSnelheidVerhogen->TabIndex = 2;
			this->buttonSnelheidVerhogen->Text = L"+";
			this->buttonSnelheidVerhogen->UseVisualStyleBackColor = true;
			this->buttonSnelheidVerhogen->Click += gcnew System::EventHandler(this, &Form1::buttonSnelheidVerhogen_Click);
			// 
			// buttonSnelheidVerlagen
			// 
			this->buttonSnelheidVerlagen->Location = System::Drawing::Point(212, 169);
			this->buttonSnelheidVerlagen->Name = L"buttonSnelheidVerlagen";
			this->buttonSnelheidVerlagen->Size = System::Drawing::Size(32, 23);
			this->buttonSnelheidVerlagen->TabIndex = 3;
			this->buttonSnelheidVerlagen->Text = L"-";
			this->buttonSnelheidVerlagen->UseVisualStyleBackColor = true;
			this->buttonSnelheidVerlagen->Click += gcnew System::EventHandler(this, &Form1::buttonSnelheidVerlagen_Click);
			// 
			// ScrollBarKoppeling
			// 
			this->ScrollBarKoppeling->Location = System::Drawing::Point(292, 205);
			this->ScrollBarKoppeling->Name = L"ScrollBarKoppeling";
			this->ScrollBarKoppeling->Size = System::Drawing::Size(19, 194);
			this->ScrollBarKoppeling->TabIndex = 5;
			// 
			// ScrollBarRem
			// 
			this->ScrollBarRem->Location = System::Drawing::Point(362, 205);
			this->ScrollBarRem->Name = L"ScrollBarRem";
			this->ScrollBarRem->Size = System::Drawing::Size(19, 194);
			this->ScrollBarRem->TabIndex = 6;
			// 
			// ScrollBarGas
			// 
			this->ScrollBarGas->Location = System::Drawing::Point(431, 205);
			this->ScrollBarGas->Name = L"ScrollBarGas";
			this->ScrollBarGas->Size = System::Drawing::Size(19, 194);
			this->ScrollBarGas->TabIndex = 7;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 40, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point, 
				static_cast<System::Byte>(0)));
			this->label1->Location = System::Drawing::Point(4, 88);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(174, 63);
			this->label1->TabIndex = 8;
			this->label1->Text = L"0km/h";
			// 
			// buttonActivatie
			// 
			this->buttonActivatie->Location = System::Drawing::Point(12, 169);
			this->buttonActivatie->Name = L"buttonActivatie";
			this->buttonActivatie->Size = System::Drawing::Size(75, 23);
			this->buttonActivatie->TabIndex = 9;
			this->buttonActivatie->Text = L"Activatie";
			this->buttonActivatie->UseVisualStyleBackColor = true;
			this->buttonActivatie->Click += gcnew System::EventHandler(this, &Form1::buttonActivatie_Click);
			// 
			// labelIngesteldeSnelheid
			// 
			this->labelIngesteldeSnelheid->AutoSize = true;
			this->labelIngesteldeSnelheid->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 40, System::Drawing::FontStyle::Regular, 
				System::Drawing::GraphicsUnit::Point, static_cast<System::Byte>(0)));
			this->labelIngesteldeSnelheid->Location = System::Drawing::Point(321, 88);
			this->labelIngesteldeSnelheid->Name = L"labelIngesteldeSnelheid";
			this->labelIngesteldeSnelheid->Size = System::Drawing::Size(174, 63);
			this->labelIngesteldeSnelheid->TabIndex = 12;
			this->labelIngesteldeSnelheid->Text = L"0km/h";
			// 
			// labelIngesteld
			// 
			this->labelIngesteld->AutoSize = true;
			this->labelIngesteld->Location = System::Drawing::Point(262, 126);
			this->labelIngesteld->Name = L"labelIngesteld";
			this->labelIngesteld->Size = System::Drawing::Size(53, 13);
			this->labelIngesteld->TabIndex = 13;
			this->labelIngesteld->Text = L"Ingesteld:";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(276, 417);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(54, 13);
			this->label2->TabIndex = 14;
			this->label2->Text = L"Koppeling";
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(359, 417);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(29, 13);
			this->label3->TabIndex = 15;
			this->label3->Text = L"Rem";
			// 
			// label4
			// 
			this->label4->AutoSize = true;
			this->label4->Location = System::Drawing::Point(428, 417);
			this->label4->Name = L"label4";
			this->label4->Size = System::Drawing::Size(26, 13);
			this->label4->TabIndex = 16;
			this->label4->Text = L"Gas";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(537, 486);
			this->Controls->Add(this->label4);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->labelIngesteld);
			this->Controls->Add(this->labelIngesteldeSnelheid);
			this->Controls->Add(this->buttonActivatie);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->ScrollBarGas);
			this->Controls->Add(this->ScrollBarRem);
			this->Controls->Add(this->ScrollBarKoppeling);
			this->Controls->Add(this->buttonSnelheidVerlagen);
			this->Controls->Add(this->buttonSnelheidVerhogen);
			this->Controls->Add(this->buttonPauze);
			this->Controls->Add(this->buttonStartAuto);
			this->Name = L"Form1";
			this->Text = L"Cruise control simulatie";
			this->FormClosing += gcnew System::Windows::Forms::FormClosingEventHandler(this, &Form1::Form1_FormClosing);
			this->FormClosed += gcnew System::Windows::Forms::FormClosedEventHandler(this, &Form1::Form1_FormClosed);
			this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
		#pragma endregion

	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
			 }

			 

	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			
				autogestart_event = (event*)malloc(sizeof(event));			//maakt geheugen vrij voor het event
				create_event(autogestart_event,0);							//zet het event op 0, of te wel inactief
				autohoofd = (task*)malloc(sizeof(task));				//maakt geheugen vrij voor de taak
				Gegevens g ;												//declareert het mee te geven gegevens bestand
				g.initklaar = autogestart_event;							//zet de referentie van het event in g op de goede plaats
				create_task(autohoofd,Initialiseer,&g,sizeof(Gegevens),0);	//start de taak
				wait_event(autogestart_event);								//wacht op event
				g.formData = eigenData;
														//verwijdert de taak uit het geheugen
			 }
	private: System::Void Form1_FormClosed(System::Object^  sender, System::Windows::Forms::FormClosedEventArgs^  e) {

			 }

	private: System::Void buttonSnelheidVerhogen_Click(System::Object^  sender, System::EventArgs^  e) {
				input.snelheid += 1;
				UpdateData();
			 }

	private: System::Void buttonPauze_Click(System::Object^  sender, System::EventArgs^  e) {
				input.knop = pauzeknop;
				UpdateData();
			 }

	private: System::Void buttonSnelheidVerlagen_Click(System::Object^  sender, System::EventArgs^  e) {
				if(input.snelheid>0)
				{
				 input.snelheid -= 1;
				 UpdateData();
				}
			 }

	private: System::Void buttonActivatie_Click(System::Object^  sender, System::EventArgs^  e) {
				input.knop = activatie;
				UpdateData();
			 }

			 private: System::Void UpdateData()
			 {
				 put_mailBox(eigenData,&input);
			 }
private: System::Void Form1_FormClosing(System::Object^  sender, System::Windows::Forms::FormClosingEventArgs^  e) {
			delete(autohoofd);	
		 }
};
}

